package it.lorenz.server.fk.business;

import it.lorenz.server.fk.business.ex.AbstractBusinessException;
import it.lorenz.server.fk.business.ex.ValidationException;
import org.springframework.stereotype.Component;

@Component("businessManager")
public class BusinessManager {

    public AbstractDTO executeBusinessProcess(AbstractDTO dto,
       IBusinessProcess businessProcess) throws ValidationException, AbstractBusinessException {
        try {
            while (businessProcess.hasNext()) {
                IService businessService = businessProcess.next();
                businessService.doFormalValidation(dto);
                businessService.doFunctionalValidation(dto);
                dto = businessService.processDTOIn(dto);
                dto = businessService.callBusinessService(dto);
                dto = businessService.processDTOOut(dto);
            }
        } catch (AbstractBusinessException abe) {
            throw abe;
        } catch (ValidationException ve) {
            throw ve;
        } finally {
        }
        return dto;
    }
}